/***************************************************************************
 *   Copyright (C) 2009 by Marian Skvarek   *
 *   skvarek.marian@gmail.com   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A TrackICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
 
#include "CPartDrumsView.h"
#include "CPartDrums.h"

#include "CScoreView.h"
#include "CTrackView.h"

namespace easyscore
{
	namespace core
	{

//Constructors, Initialization & Destructors
		CPartDrumsView::CPartDrumsView ( CPartDrums * model )
		{
			mModel = model;
		}
		
		void CPartDrumsView::initialize ()
		{
			CPartView::initialize();
					
			update();
		}
		
		void CPartDrumsView::clear ()
		{
			CPartView::clear();
		}


		CPartDrumsView::~CPartDrumsView()
		{
			clear();
		}
		
//Public methods
		void CPartDrumsView::update ()
		{
			CPartView::update();
			
			initializeTrackView(mModel->getTrack());					
			getTrackView()->setPos(0,0);
			
			refreshLayout();
		}
		
		void CPartDrumsView::refreshLayout ()
		{
			CPartView::refreshLayout();
			
			int w = 0;
			if(mModel->getTrack().hasView())
				w = getTrackView()->rect().width();
			int h = 0;
			if(mModel->getTrack().hasView())
				h = getTrackView()->rect().height();
			
			
			
			setRect(rect().x(), rect().y(), w, h );
			
			mScoreView->refreshLayout();
		}
		
//Protected methods
		CTrackView *CPartDrumsView::getTrackView() 
		{ 
			return mModel->getTrack().getView(); 
		}
		
		void CPartDrumsView::initializeTrackView(CTrack &track)
		{
			if(!track.hasView())
			{
				track.createView();
				track.getView()->setPartView(this);
				track.getView()->initialize();
			}
		}

	}//namespace core
}//namespace easyscore
